// Copyright (C) 2010  Joan Puigcerver Perez, <joapuipe@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#include <LogUtils.hpp>

std::string get_datetime(void)
{
  time_t t = time(0);
  tm * curr_t = localtime(&t);
  char str_time[50];
  strftime(str_time, 50, "%Y/%m/%d %H:%M:%S", curr_t);
  return std::string( str_time );
}

void print_log_line(const std::string& line, std::ostream& logf, ost::Mutex& mutex)
{
  mutex.enterMutex();
  logf << get_datetime() << " " << line << std::endl;
  mutex.leaveMutex();
}
